package com.kxf.androidtestdemo.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.kxf.androidtestdemo.R;
import com.kxf.androidtestdemo.view.MyScrollView;

public class ScrollViewActivity extends BaseActivity {

    private MyScrollView my_sv;
    private MyScrollView.OnMyScrollListener listener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scroll_view);
        my_sv = findViewById(R.id.my_sv);

        listener = new MyScrollView.OnMyScrollListener() {
            @Override
            public void onScrollStateChanged(MyScrollView view, int state) {
                String str;
                if (state == 0) {
                    str = "IDLE";
                } else if (state == 1) {
                    str = "DRAG";
                } else if (state == 2) {
                    str = "FLING";
                } else {
                    str = "ERROR";
                }
                Log.d("ScrollViewActivity", "滑动状态：" + str);
            }

            @Override
            public void onScroll(MyScrollView view, int y) {
//                Log.d("ScrollViewActivity", "onScroll====" + y);

            }

            @Override
            public void onScrollToTop() {
                Log.d("ScrollViewActivity", "滑到顶部");
            }

            @Override
            public void onScrollToBottom() {
                Log.d("ScrollViewActivity", "滑动底部");
            }

            @Override
            public void onDownRefreshStart() {
                Log.d("ScrollViewActivity", "用户想要下拉刷新，但是还没放下按钮");
            }

            @Override
            public void onDownRefreshSuccess() {
                Log.d("ScrollViewActivity", "完成下拉刷新动作");
            }

            @Override
            public void onDownRefreshcancel() {
                Log.d("ScrollViewActivity", "取消下拉刷新动作");
            }
        };
    }

    @Override
    protected void onResume() {
        super.onResume();
        my_sv.addOnScrollListner(listener);
    }

    @Override
    public void onLocalVoiceInteractionStopped() {
        super.onLocalVoiceInteractionStopped();
        my_sv.removeOnScrollListener(listener);
    }

    public void onClickTop(View view) {
        my_sv.fullScroll(View.FOCUS_UP);
    }
}
